﻿using System;
using System.Configuration;
using iTransact;
using iTransact.Requests;
using iTransact.Responses;

namespace Console
{
	class Program
	{
		static void Main(string[] args)
		{
			var chargeRequest = new ChargeRequest()
									{
										iTransactApiKey = ConfigurationManager.AppSettings["iTransactApiKey"],
										iTransactGateway = ConfigurationManager.AppSettings["iTransactApiKey"],
										iTransactUserName = ConfigurationManager.AppSettings["iTransactUsername"],
										BillingAddress = "123 Test Rd.",
										BillingCity = "Orlando",
										BillingState = "FL",
										BillingZip = "34787",
										BillingCountry = "US",
										BillingFirstName = "Billy",
										BillingLastName = "Bob",
										BillingPhone = "111-111-1111",

										Email = "tjgarlick@gmail.com",

										// Optional
										//ShippingAddress = "123 Test Rd.",
										//ShippingCity = "Orlando",
										//ShippingState = "FL",
										//ShippingZip = "34787",
										//ShippingCountry = "US",
										//ShippingFirstName = "Billy",
										//ShippingLastName = "Bob",
										//ShippingPhone = "111-111-1111",

										CreditCardNumber = "5454545454545454",
										Cvv = "111",
										ExpirationMonth = DateTime.Now.AddMonths(1).Month > 10 ? DateTime.Now.AddMonths(1).Month.ToString() : "0" + DateTime.Now.AddMonths(1).Month,
										ExpirationYear = DateTime.Now.Year.ToString(),

										OrderItems = new[]
										             	{
										             		new OrderItem() { Cost = 12.99m, Description = "Monthy Bill", Quantity = 1 }, 
															new OrderItem() { Cost = 2.99m, Description = "Shipping", Quantity = 1 }, 
															new OrderItem() { Cost = 12.99m, Description = "Tax", Quantity = 1 }
										             	},
										CustomerId = "1234"
									};

			var response = PaymentProcessor.ChargeCreditCard(chargeRequest);

			if (response.Status == TransactionStatus.Ok)
			{
				System.Console.WriteLine("Transaction OK");
				System.Console.WriteLine("Transaction Id:  " + response.TransactionId);
			}
			else
			{
				System.Console.WriteLine("ERROR!!!!");
				System.Console.WriteLine("AVS Error:  " + response.Avs);
				System.Console.WriteLine("Error Message:  " + response.ErrorMessage);
				System.Console.WriteLine("Xml:  " + response.RawXml);
			}

			System.Console.ReadLine();
		}
	}
}
